<?php
/**
 * Rule Popup 
 * Edit a conversion rule
 * 
 * @author Xavier VILAIN
 * @package Orx\Etl\Extractor\Item
 * @license #license-orx-etl#
 * 
 */

use Fox\Popup;
use Fox\Html\TextArea;
use Fox\Html\Screen;
use Orx\Etl\Extractor;
$xview = Xview::instance();
$extractorid = $xview->val('extractor',false);
$position = $xview->val('position',false);
try {
	$extractor = Fox\Dao::load(Extractor::className(),$extractorid);
	$item = $extractor->findItems($extractorid.':'.$position);
	$data = $item->getData();
}
catch(Fox\Object\Exception\NotExist $e) {
	Fox\Message::Error($e);
}
$label = Msg(Orx\Etl::BUNDLE,Orx\Etl::CONVERSION_RULE);
$screen = new Screen('sRule','update',null,true);
$screen->block()
		->noLegend()
		->add(new TextArea(array('etl_conversion_rule','conversion_rule'),false,null,160,25))
		->size(9990);
$screen->initialize($data);
		
if($screen->submitted()) {
	$fields = $screen->get();
	if(!$screen->errors()) {
		try {
			$item->setFields(array('conversion_rule' => $fields['conversion_rule']));
			$item->update();
			Fox\Message::Success(Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_UPDATE,$label));
		}
		catch(Fox\Object\Exception\Save $e) {
			Fox\Message::Error($e);
		}
		echo $xview->messages(true,true);
		exit;
	}
}
$popup = new Popup('pRule',$label,$screen,700);
echo $popup->display();